<?php

class module_u_cart extends a_base_module
implements i_hook_pre_controller,
           i_hook_post_controller,
           i_hook_post_controller_constructor,
           i_hook_post_system,
           i_hook_base_controller_constructor{    
    
    private $srv ;
    public function __construct($basic_info){
        parent::__construct($basic_info);
        $this->srv = new service_l_cart();
    }

    public function exe_pre_controller(){


    }

    public function exe_post_controller(){

    }

    public function exe_post_controller_constructor(){        
        
        get_instance()->smarty_wrapper->assign("cart",$this->srv->get_cart());
        $this->__add_single_item();
    }

    private function __add_single_item(){
        $ci = $this->ci();
        if($ci->input->post("cart_singe_item")){
            $part_id = $ci->input->post("cart_part_id");
            $qty     = $ci->input->post("cart_qty");
            try {
                $this->srv->get_cart()->add_item($part_id,$qty);
            }
            catch (Exception $exc) {
                logger::i()->error($exc->getMessage(), "add single item");
                //@TO_DO catch product not found, invalid qty etc error and respond accordingly
            }
        }
    }

    public function exe_post_system(){
       // trace();
    }

    public function exe_base_controller_constructor(){

    }

//    public static function exe_pre_system(){
//        echo "ok";
//    }

}
?>